package com.inspur.sc.springboot.service.impl;

import com.inspur.sc.springboot.dao.SysGroupRoleDao;
import com.inspur.sc.springboot.dao.SysRoleDao;
import com.inspur.sc.springboot.entity.SysGroupRole;
import com.inspur.sc.springboot.entity.SysRole;
import com.inspur.sc.springboot.service.SysGroupRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Slf4j
@Service
public class SysGroupRoleServiceImpl implements SysGroupRoleService {

    @Autowired
    private SysGroupRoleDao groupRoleDao;

    @Autowired
    private SysRoleDao roleDao;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean save(SysGroupRole groupRole) {
        try{
            groupRoleDao.save(groupRole);
            return true;
        }catch (Exception e){
            log.error(e.getMessage());
            return false;
        }
    }

    @Override
    public List<SysRole> findRoleByGroupId(Integer groupId) {
        return roleDao.findSysRoleByGroupId(groupId);
    }
}
